
TRIGGER PROCEDURE FOR DELETE OF AP_MSTR.

/*fdn*/    {mfdeclre.i }
/*fdn*/    define new shared work-table wf_old_ap_mstr like ap_mstr.

HK:
do:
    if can-find(first dt_mstr where dt_table = "ap_mstr" and dt_type = "SYNC") then
        run CreateSyncFlag(input "DEL", input recid(ap_mstr), input "ap_mstr").

    if not can-find ( first dt_mstr where dt_table = "ap_mstr" and dt_type = "DEL" ) then leave HK.
    
    if not can-find ( first wf_old_ap_mstr ) then do:
        create wf_old_ap_mstr.
        if recid(wf_old_ap_mstr)= -1 then .
    end.
    
    buffer-copy ap_mstr to wf_old_ap_mstr no-error.

    for first dt_mstr no-lock where dt_table = "ap_mstr" and dt_type = "DEL" :
    
        run CreateDthist(input dt_table, input dt_field, input dt_type, input "", input "", 
            input recid(ap_mstr), input ap_mstr.ap_type, input ap_mstr.ap_ref, input "", input "",
            input "", input "", input "", input "") .
		
    end.
end.

{hkdttrans.i}
